/**
* @file gui_pointer_frontend.h
* @brief mouse or tp frontend
* @details 
* @author huangbin
* @version V1.0.0
* @date 2025-06-12
* @copyright All documents are copyrighted by Shenzhen Xinlongwei Technology Co., LTD.
*            They may not be used for commercial purposes without permission
*/


#ifndef __GUI_POINTER_FRONTEND_H__
#define __GUI_POINTER_FRONTEND_H__

/*============================ INCLUDES ======================================*/
#include "../gui_cfg.h"

#include "../gui_message.h"

#ifdef   __cplusplus
extern "C" {
#endif

#if defined(__clang__)
#   pragma clang diagnostic push
#   pragma clang diagnostic ignored "-Wmissing-declarations"
#   pragma clang diagnostic ignored "-Wmicrosoft-anon-tag"
#   pragma clang diagnostic ignored "-Wpadded"
#endif

/*============================ MACROS ========================================*/

/* OOC header, please DO NOT modify  */
#ifdef __GUI_POINTER_FRONTEND_IMPLEMENT__
#   undef   __GUI_POINTER_FRONTEND_IMPLEMENT__
#   define  __ARM_2D_IMPL__
#elif defined(__GUI_POINTER_FRONTEND_INHERIT__)
#   undef   __GUI_POINTER_FRONTEND_INHERIT__
#   define __ARM_2D_INHERIT__
#endif
#include "arm_2d_utils.h"

/*============================ MACROS ========================================*/
/*============================ MACROFIED FUNCTIONS ===========================*/
/*============================ TYPES =========================================*/

typedef struct gui_msg_pointer_frontend_pipeline_t{
ARM_PRIVATE(
    uint8_t chPT[3];

    uint8_t u4Index                 : 4;
    uint8_t bReceivedPointerMove    : 1;
    uint8_t                         : 3;

    gui_helper_msg_fifo_t tFIFO[3];

    struct {
        void *ptTargetWidgets;
        arm_2d_location_t tLastPoint;
    } Stage1;

    struct {
        void *ptTargetWidgets;
        arm_2d_location_t tLastPoint;
    } Stage2;

    struct {
        gui_helper_msg_fifo_t tClickFIFO;
    } Stage3;

    int64_t lTimestamp[4];
)
}gui_msg_pointer_frontend_pipeline_t;

typedef struct gui_msg_pointer_frontend_cfg_t {
    uint16_t hwLongPressThreshold;
    uint16_t hwHoverThreshold;
    uint16_t u10DoubleClickLimit            : 10;
    uint16_t                                : 5;
    uint16_t bRemoveUnexpectedMessage       : 1;

} gui_msg_pointer_frontend_cfg_t;


typedef struct gui_msg_pointer_frontend_t {
    implement(gui_msg_frontend_t);       /* base */

ARM_PRIVATE(
    gui_msg_pointer_frontend_cfg_t tCFG;
    
    uint8_t chDispatcherPT;

    struct {
        uint8_t chNumber;
        gui_msg_pointer_frontend_pipeline_t *ptPipelines;
    } Pointers;
)

} gui_msg_pointer_frontend_t;

/*============================ GLOBAL VARIABLES ==============================*/
/*============================ PROTOTYPES ====================================*/

ARM_PUBLIC_METHOD(

    extern
    ARM_NONNULL(1)
    arm_2d_err_t gui_helper_msg_pointer_frontend_init(  
                                        gui_msg_pointer_frontend_t *ptThis,
                                        gui_msg_pointer_frontend_cfg_t *ptCFG,
                                        gui_msg_pointer_frontend_pipeline_t *ptPipelines,
                                        uint_fast8_t chPipelineNo);

    extern
    ARM_NONNULL(1, 2)
    gui_msg_pointer_frontend_cfg_t *gui_helper_msg_pointer_frontend_settings_get(
                                        gui_msg_pointer_frontend_t *ptThis,
                                        gui_msg_pointer_frontend_cfg_t *ptCFG);
    
    extern
    ARM_NONNULL(1, 2)
    void gui_helper_msg_pointer_frontend_settings_set(
                                        gui_msg_pointer_frontend_t *ptThis,
                                        gui_msg_pointer_frontend_cfg_t *ptCFG);

)

#if defined(__clang__)
#   pragma clang diagnostic pop
#endif

#ifdef   __cplusplus
}
#endif

#endif
